package cn.wolfcode.service.impl;

import cn.wolfcode.domain.ActivityItem;
import cn.wolfcode.domain.Choice;
import cn.wolfcode.exception.LogicException;
import cn.wolfcode.mapper.ActivityItemMapper;
import cn.wolfcode.mapper.ChoiceMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IActivityItemService;
import cn.wolfcode.util.UserContext;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ActivityItemServiceImpl implements IActivityItemService {

    @Autowired
    private ActivityItemMapper activityItemMapper;

    @Autowired
    private ChoiceMapper choiceMapper;
    @Override
    public void save(Long id, Long activityId) {

        activityItemMapper.updateByPrimaryKey(id);
        //获取员工的id
        Choice choice = new Choice();
        choice.setActivityItemId(activityId);
        choice.setEmployeeId(UserContext.getCurrentUser().getId());
        choice.setCreateTime(new Date());
        choiceMapper.insert(choice);
    }

    @Override
    public void delete(Long id) {
        activityItemMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(ActivityItem activityItem) {
    }

    @Override
    public ActivityItem get(Long id) {
        return activityItemMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ActivityItem> listAll() {
        return activityItemMapper.selectAll();
    }

    @Override
    public PageInfo<ActivityItem> query(QueryObject qo) {
       return null;
    }

    @Override
    public List<ActivityItem> selectByActivityId(Long id) {
        return activityItemMapper.selectByActivityId(id);
    }
}
